using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bAccount
    {
        public static int insertAccount(eAccount account)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@AccountID", SqlDbType.VarChar);
            pr.Value =account.AccountID;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailID", SqlDbType.Int);
            pr.Value = account.PlanDetailID;
            paramList.Add(pr);

            pr = new SqlParameter("@CustomerID", SqlDbType.Int);
            pr.Value = account.CustomerID;
            paramList.Add(pr);

            pr = new SqlParameter("@Status", SqlDbType.Int);
            pr.Value = account.Status;
            paramList.Add(pr);

            int r= dbh.ExecuteNonQuery("insertAccount",CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int updateAccount(eAccount account)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@AccountID", SqlDbType.VarChar);
            pr.Value = account.AccountID;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailID", SqlDbType.Int);
            pr.Value = account.PlanDetailID;
            paramList.Add(pr);

            pr = new SqlParameter("@CustomerID", SqlDbType.Int);
            pr.Value = account.CustomerID;
            paramList.Add(pr);

            pr = new SqlParameter("@Status", SqlDbType.Int);
            pr.Value = account.Status;
            paramList.Add(pr);

            int r= dbh.ExecuteNonQuery("updateAccount", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();

            return r;
        }
        public static int updateStatusAccount(String accountID,int status)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@AccountID", SqlDbType.VarChar);
            pr.Value = accountID;
            paramList.Add(pr);

            pr = new SqlParameter("@Status", SqlDbType.Int);
            pr.Value = status;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updateStatusAccount", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }
        public static int deleteAccount(String accountID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@AccountID", SqlDbType.VarChar);
            pr.Value = accountID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteAccount", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllAccount()
        {
            DBHelper dbh=new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllAccount", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static eAccount getAccountByID( string   AccountID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@AccountID", SqlDbType.VarChar);
            pr.Value = AccountID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eAccount), "getAccountByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eAccount)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
